package com.itheima.controller;


import com.itheima.domain.Book;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
    @PostMapping
    public String save(@RequestBody Book book) {
        System.out.println("book save==>"+book);
        return "{'module':'book save success'}";
    }

    @GetMapping
    public List<Book> getAll(){
        System.out.println("book getAll is running");
        List<Book> bookList = new ArrayList<Book>();

        Book book1= new Book();
        book1.setType("计算机");
        book1.setName("Spring MVC1");
        book1.setDescription("小试牛刀");
        bookList.add(book1);

        Book book2= new Book();
        book1.setType("计算机");
        book1.setName("Spring MVC2");
        book1.setDescription("身经百战");
        bookList.add(book1);

        return bookList;
    }
}
